#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const double INF = 2e18;

int n, K;
struct KD {
  int ch[2];
  int v[2];
  int L[2], U[2];
  bool operator<(const KD& o) const { return v[K] < o.v[K]; }
} tr[N];
#define lc(p) tr[p].ch[0]
#define rc(p) tr[p].ch[1]
#define v(p, k) tr[p].v[k]
#define L(p, k) tr[p].L[k]
#define U(p, k) tr[p].U[k]

void pushup(int p) {
  rep(k, 0, 1) {
    L(p, k) = U(p, k) = v(p, k);
    if (lc(p)) {
      L(p, k) = min(L(p, k), L(lc(p), k));
      U(p, k) = max(U(p, k), U(lc(p), k));
    }
    if (rc(p)) {
      L(p, k) = min(L(p, k), L(rc(p), k));
      U(p, k) = max(U(p, k), U(rc(p), k));
    }
  }
}
int build(int k, int l, int r) {
  if (l > r) return 0;
  int m = (l + r) >> 1;
  K = k;
  nth_element(tr + l, tr + m, tr + r + 1);
  lc(m) = build(k ^ 1, l, m - 1);
  rc(m) = build(k ^ 1, m + 1, r);
  pushup(m);
  return m;
}
double sq(double x) { return x * x; }
int now[2];
double dis(int p) {
  if (!p) return INF;
  double s = 0;
  rep(k, 0, 1) s += sq(v(p, k) - now[k]);
  return s;
}
double dis2(int p) {
  if (!p) return INF;
  double s = 0;
  rep(k, 0, 1) s += sq(max(0, L(p, k) - now[k]) + max(0, now[k] - U(p, k)));
  return s;
}
double ans;
void query(int p) {
  if (!p) return;
  ans = min(ans, dis(p));
  double d1 = dis2(lc(p)), d2 = dis2(rc(p));
  if (d1 <= d2) {
    if (d1 < ans) query(lc(p));
    if (d2 < ans) query(rc(p));
  } else {
    if (d2 < ans) query(rc(p));
    if (d1 < ans) query(lc(p));
  }
}
void solve() {
  cin >> n;
  rep(i, 1, n) cin >> v(i, 0) >> v(i, 1);
  int rt = build(0, 1, n);
  ans = INF;
  rep(i, 1, n) {
    cin >> now[0] >> now[1];
    query(rt);
  }
  cout << fixed << setprecision(3) << sqrt(ans) << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}